Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mini-events

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mini-events

🍰 一个mini事件管理器

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

mini-events NPM Version NPM Downloads codecov CircleCI

:cake: 一个mini的事件管理器, 希望能在您的代码中做一块砖, 支持node/browser.

安装

npm i -S mini-events

使用

import EventEmitter from  'mini-events';
const emitter = new EventEmitter();
emitter.on('add', data=>{
    console.log(data) // 1
});
emitter.emit('add', 1);

方法

on(eventName, listener)

绑定事件

名称类型数据类型是否必填说明
eventName参数`StringSymbol`
listener参数Function对应的回调函数
emitter返回值EventEmitter---实例

off(eventName, listener)

解除绑定, 如果不填写listener, 那么eventName对应的listener都会被移除.

名称类型数据类型是否必填说明
eventName参数`StringSymbol`
listener参数Function对应的回调函数
emitter返回值EventEmitter---实例
const callback = data=>{
    alert(data)
};
emitter.on('add', callback);
// 解除绑定
emitter.on('off', callback);
// add事件不会触发
emitter.emit('add', 1);

once(eventName, listener)

绑定事件, 只触发一次

名称类型数据类型是否必填说明
eventName参数`StringSymbol`
listener参数Function对应的回调函数
emitter返回值EventEmitter---实例
const callback = data=>{
    alert(data)
};
emitter.once('add', callback);
// add事件触发
emitter.emit('add', 1);
// add事件不会触发
emitter.emit('add', 1);

emit(eventName [, ...args])

触发事件, 支持任意数量参数

名称类型数据类型是否必填说明
eventName参数`StringSymbol`
...args参数Any对应的回调函数
emitter返回值Boolean---实例
const callback = (a,b,c,d)=>{
    console(a,b,c,d); // 1,2,3,4
};
emitter.once('add', callback);
// add事件触发
emitter.emit('add', 1,2,3,4);

destroy()

销毁实例

const callback = (a,b,c,d)=>{
    console(a,b,c,d); // 1,2,3,4
};
emitter.once('add', callback);
emitter.destroy();

// add事件不会触发
emitter.emit('add', 1,2,3,4);

FAQs

Package last updated on 27 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc